package i18n;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class JMenuI18N extends JMenu {
	private ActionListener actionListener;

	public JMenuI18N(String text, String actionCommand, ActionListener actionListener) {
		this(actionCommand, actionListener, null);
		this.setText(text);
	}
	
	public JMenuI18N(String actionCommand, ActionListener actionListener, String[][] menu) {
		super(actionCommand);
		this.actionListener = actionListener;
		if (menu!=null) addMenu(menu);
	}
	
	public void setText(String key) {
		super.setText(LanguageUtils.getMessage(key));
	}

	public void addMenu(String[][] menu) {
		JMenuItemI18N menuItemI18N=null;
		for (String[] menuItem: menu) {
			menuItemI18N = addMenuItem(menuItem[0], menuItem[1]);
			if (menuItem.length==3) menuItemI18N.setEnabled(false);
		}
	}
	
	public JMenuItemI18N addMenuItem(String text, String actionCommand) {
		JMenuItemI18N menuItem;
		menuItem = new JMenuItemI18N(text, actionCommand, this.actionListener);
		add(menuItem);	
		return menuItem;
	}

	
}
